<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>


<div>
  <input type="text" v-model="num1">
    <input type="button" value="加" @click="fun('+')">
    <input type="button" value="减" @click="fun('-')">
    <input type="button" value="乘" @click="fun('*')">
    <input type="button" value="除" @click="fun('/')">
  <input type="text" v-model="num2">

    <h3>结果为{{result}}</h3>

</div>


<script src="../js/vue.js"></script>
<script>
    let v = new Vue({
        el:"div",
        data:{
            num1:"",
            num2:"",
            result:""
        },
        methods:{
            fun(x){
                //eval()方法可以将字符以代码的形式执行
                v.result=eval(v.num1+x+v.num2);
            }
        }
    })

</script>
</body>
</html>